<template>
  <div class="app-container">
    <el-form label-position="left" label-width="100px" :model="readerForm" :rules="rules">

      <el-form-item label="任务状态" prop="status">
            <el-radio v-for="(item, index) in dictList('is_use')" :key="index" v-model="readerForm.status" :label="item.value">
              {{ item.label }}
            </el-radio> 
          </el-form-item>
          <el-form-item label="数据集名称" prop="extractionName">
            <el-input v-model="readerForm.extractionName" />
          </el-form-item>
   
     
      <el-form-item label="源端表">
        <el-checkbox
          v-model="readerForm.lcheckAll"
          :indeterminate="readerForm.isIndeterminate"
          @change="lHandleCheckAllChange"
        >全选</el-checkbox>
        <div style="margin: 15px 0;" />
        <el-checkbox-group v-model="readerForm.ltables" @change="lHandleCheckedChange">
          <el-checkbox v-for="c in fromTablesList" :key="c.id" :label="c">{{ c.columnName}}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="目标表">
        <el-checkbox
          v-model="readerForm.rcheckAll"
          :indeterminate="readerForm.isIndeterminate"
          @change="rHandleCheckAllChange"
        >全选</el-checkbox>
        <div style="margin: 20px 0;" />
        <el-checkbox-group v-model="readerForm.rtables" @change="rHandleCheckedChange">
          <el-checkbox v-for="c in toTablesList" :key="c.id" :label="c">{{ c.columnName }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'TableMapper',
  data() {
    return {
      mapperJson: {},
      fromTablesList: [],
      toTablesList: [],
      readerForm: {
        ltables: [],
        rtables: [],
        lcheckAll: false,
        rcheckAll: false,
        isIndeterminate: true,
        extractionName:'',
        status:'1'
      },
      rules: {
        extractionName: [{ required: true, message: '数据集名称为必填项', trigger: 'change' }],
        status:[{ required: true, message: '任务状态为必填项', trigger: 'change' }]
      }
    }
  },
  mounted() {
  },
  methods: {
    rest(){
      this.fromTablesList=[]
      this.toTablesList=[]
      this.readerForm= {
        ltables: [],
        rtables: [],
        lcheckAll: false,
        rcheckAll: false,
        isIndeterminate: true,
        extractionName:'',
        status:'1'
      }
    },
    lHandleCheckAllChange(val) {
      this.readerForm.ltables = val ? this.fromTablesList : []
      this.readerForm.isIndeterminate = false
    },
    rHandleCheckAllChange(val) {
      this.readerForm.rtables = val ? this.toTablesList : []
      this.readerForm.isIndeterminate = false
    },
    lHandleCheckedChange(value) {
      const checkedCount = value.length
      this.readerForm.lcheckAll = checkedCount === this.fromTablesList.length
      this.readerForm.isIndeterminate = checkedCount > 0 && checkedCount < this.fromTablesList.length
    },
    rHandleCheckedChange(value) {
      const checkedCount = value.length
      this.readerForm.rcheckAll = value.length === this.toTablesList.length
      this.readerForm.isIndeterminate = checkedCount > 0 && checkedCount < this.toTablesList.length
    },
    getLTables() {
      return this.readerForm.ltables
    },
    getRTables() {
      return this.readerForm.rtables
    },
    getName() {
      return this.readerForm
    }
  }
}
</script>
